﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using QLTV_Public;
using QLTV_BLL;

namespace QLTV_GiaoDien
{
    public partial class frmMain : RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
            InitSkinGallery();
           

        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }
        public void GetLoad()
        {
            //he thong
            bbi_DangXuat.Enabled = false;
            bbi_QuyenHan.Enabled = false;
            bbi_NhomNGuoiDung.Enabled = false;
            bbi_TaiKhoanNGuoiDung.Enabled = false;
            bbi_DoiMatKhau.Enabled = false;
            bbi_SaoLuu.Enabled = false;
            bbi_PhucHoi.Enabled = false;
            bbi_NhatKy.Enabled = false;
            //cập nhật
            bbi_DonVi.Enabled = false;
            bbi_Lop.Enabled = false;
            bbi_CapNhatDocGia.Enabled = false;
            bbi_CapNhatTaiLieu.Enabled = false;
            bbi_CapNhatNXB.Enabled = false;
            bbi_CapNhatTheLoai.Enabled = false;
            bbi_CapNhatNgonNgu.Enabled = false;
            bbi_CapNhatViTri.Enabled = false;
            //Mượn trả
            bbi_PhieuMuon.Enabled = false;
            bbi_DanhSachMuonTL.Enabled = false;
            //bbi_CapNhatMuonTaiLieu.Enabled = false;
            bbi_MuonSach.Enabled = false;
            bbi_TraSach.Enabled = false;
            bbi_PMQuaHan.Enabled = false;
            bbi_XLVP.Enabled = false;
            ////Thống kê
            bbi_ThongKeDocGiaMuonSach.Enabled = false;
            bbi_ThongKeTraQuaHan.Enabled = false;
            bbi_ThongKeTLDangMuon.Enabled = false;
            bbi_ThongKeTheLoai.Enabled = false;
            bbi_ThongKeViPham.Enabled = false;
            ////Tìm kiếm
            bbi_TimKiemDocGia.Enabled = false;
        }
        public void GetLoad_QuanLy()
        {
            //he thong
            bbi_DangXuat.Enabled = true;
            bbi_QuyenHan.Enabled = true;
            bbi_NhomNGuoiDung.Enabled = true;
            bbi_TaiKhoanNGuoiDung.Enabled = true;
            bbi_DoiMatKhau.Enabled = true;
            bbi_SaoLuu.Enabled = true;
            bbi_PhucHoi.Enabled = true;
            bbi_NhatKy.Enabled = true;
            //cập nhật
            bbi_DonVi.Enabled = true;
            bbi_Lop.Enabled = true;
            bbi_CapNhatDocGia.Enabled = true;
            bbi_CapNhatTaiLieu.Enabled = true;
            bbi_CapNhatNXB.Enabled = true;
            bbi_CapNhatTheLoai.Enabled = true;
            bbi_CapNhatNgonNgu.Enabled = true;
            bbi_CapNhatViTri.Enabled = true;
            //Mượn trả
            bbi_PhieuMuon.Enabled = true;
            bbi_DanhSachMuonTL.Enabled = true;
            bbi_MuonSach.Enabled = true;
            bbi_TraSach.Enabled = true;
            bbi_PMQuaHan.Enabled = true;
            bbi_XLVP.Enabled = true;
            //Thống kê
            bbi_ThongKeDocGiaMuonSach.Enabled = true;
            bbi_ThongKeTraQuaHan.Enabled = true;
            bbi_ThongKeTLDangMuon.Enabled = true;
            bbi_ThongKeTheLoai.Enabled = true;
            bbi_ThongKeViPham.Enabled = true;
            //Tìm kiếm
            bbi_TimKiemDocGia.Enabled = true;
        }
        public void GetLoad_NhanVien()
        {
            //hệ thống
            bbi_DangXuat.Enabled = true;
            bbi_DoiMatKhau.Enabled = true;
            //cập nhật
            bbi_DonVi.Enabled = true;
            bbi_Lop.Enabled = true;
            bbi_CapNhatDocGia.Enabled = true;
            bbi_CapNhatTaiLieu.Enabled = true;
            bbi_CapNhatNXB.Enabled = true;
            bbi_CapNhatTheLoai.Enabled = true;
            bbi_CapNhatNgonNgu.Enabled = true;
            bbi_CapNhatViTri.Enabled = true;
            //Mượn trả
            bbi_PhieuMuon.Enabled = true;
            bbi_DanhSachMuonTL.Enabled = true;
            bbi_MuonSach.Enabled = true;
            bbi_TraSach.Enabled = true;
            bbi_PMQuaHan.Enabled = true;
            bbi_XLVP.Enabled = true;
            //Thống kê
            bbi_ThongKeDocGiaMuonSach.Enabled = true;
            bbi_ThongKeTraQuaHan.Enabled = true;
            bbi_ThongKeTLDangMuon.Enabled = true;
            bbi_ThongKeTheLoai.Enabled = true;
            bbi_ThongKeViPham.Enabled = true;
            //Tìm kiếm
            bbi_TimKiemDocGia.Enabled = true;
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            //DevExpress.LookAndFeel.DefaultLookAndFeel defaultLookAndFeel = new DevExpress.LookAndFeel.DefaultLookAndFeel();
            //defaultLookAndFeel.LookAndFeel.SkinName = "Blue";
            GetLoad();
            txt_Load.Hide();
        }


        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void bbi_DonVi_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_DonVi f = new uc_DonVi();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_Lop_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_Lop f = new uc_Lop();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_CapNhatDocGia_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_DocGia f = new uc_DocGia();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_CapNhatTaiLieu_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_TaiLieu f = new uc_TaiLieu();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_CapNhatNXB_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_NhaXuatBan f = new uc_NhaXuatBan();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_CapNhatTheLoai_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_TheLoai f = new uc_TheLoai();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_CapNhatViTri_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ViTri f = new uc_ViTri();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_PhieuMuon_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_PhieuMuonSach f = new uc_PhieuMuonSach();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_MuonSach_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_MuonTaiLieu f = new uc_MuonTaiLieu();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_TraSach_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_TraTaiLieu f = new uc_TraTaiLieu();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_PMQuaHan_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_MuonQuaHan f = new uc_MuonQuaHan();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }
        public void MyGetLoad(int kt)
        {
            txt_Load.Text = kt.ToString();
        }
        private void bbi_DangNhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            frm_DangNhap f = new frm_DangNhap();
            f.GetLoad = new frm_DangNhap.GetInt(MyGetLoad);
            f.ShowDialog();
        }

        private void bbi_QuyenHan_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_QuyenHan f = new uc_QuyenHan();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_NhomNGuoiDung_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_NhomNguoiDung f = new uc_NhomNguoiDung();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_TaiKhoanNGuoiDung_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_NguoiDung f = new uc_NguoiDung();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_DoiMatKhau_ItemClick(object sender, ItemClickEventArgs e)
        {
            frm_DoiMatKhau f = new frm_DoiMatKhau();
            f.ShowDialog();
        }

        private void barButtonItem_TimKiemTL_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_TimKiemTaiLieu f = new uc_TimKiemTaiLieu();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_CapNhatNgonNgu_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_NgonNgu f = new uc_NgonNgu();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_DanhSachMuonTL_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_DanhSachMuonTaiLieu f = new uc_DanhSachMuonTaiLieu();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                GetLoad_QuanLy();
                bbi_DangNhap.Enabled = false;
            }
            if (txt_Load.Text == "2")
            {
                bbi_DangNhap.Enabled = false;
                GetLoad_NhanVien();
            }

        }
        private void bbi_DangXuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn đăng xuất khỏi hệ thống không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                string d = DateTime.Now.ToString();
                TrungGian tg = new TrungGian();
                NhatKy_BLL nhatKy_bll = new NhatKy_BLL();
                NhatKy_Public nk = new NhatKy_Public();
                nk.MaNV = tg.MaNV;
                nk.NgayGio = d;
                nk.HanhDong = "Đăng Xuất";
                nk.MoTa = "Đăng xuất khỏi chương trình";
                nhatKy_bll.insert_nhatKy(nk,nk,nk,nk);
                //
                GetLoad();
                bbi_DangNhap.Enabled = true;
                txt_Load.Text = "0";
                panelControl1.Controls.Clear();
            }
        }

        private void iExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát chương trình không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                System.Windows.Forms.Application.Exit();
            }
        }

        private void bbi_ThongKeTheLoai_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ThongKeTheoTheLoai f = new uc_ThongKeTheoTheLoai();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_XLVP_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ViPham f = new uc_ViPham();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_ThongKeViPham_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ThongKe_ViPham f = new uc_ThongKe_ViPham();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_ThongKeDocGiaMuonSach_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_DanhSachMuonTaiLieu f = new uc_DanhSachMuonTaiLieu();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_ThongKeTraQuaHan_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ThongKeTraTLQuaHan f = new uc_ThongKeTraTLQuaHan();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_NhatKy_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_NhatKy f = new uc_NhatKy();
             panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_ThongKeTLDangMuon_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ThongKe_TaiLieuDangMuon f = new uc_ThongKe_TaiLieuDangMuon();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_TimKiemDocGia_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_TimKiemDocGia f = new uc_TimKiemDocGia();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_SaoLuu_ItemClick(object sender, ItemClickEventArgs e)
        {
            MessageBox.Show("Chức năng Sao lưu dữ liệu chưa được mở!","Thông Báo",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }

        private void bbi_PhucHoi_ItemClick(object sender, ItemClickEventArgs e)
        {
            MessageBox.Show("Chức năng Khôi Phục dữ liệu chưa được mở!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

    }
}